package azheng.apps.starclouddemo.demo;

import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;

/**
 * @author azheng
 * @date 2018/8/17.
 * GitHub：https://github.com/RookieExaminer
 * Email：wei.azheng@foxmail.com
 * Description：
 */
public class DwDemo extends AppCompatActivity {
    AnimationDrawable mAnimation1 = null;
    int mRandom = 1;//随机数
    MyView myView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        myView = new MyView(this);
        setContentView(myView);

        mRandom = (int) (Math.random() * 100);
        if (mRandom % 5 == 0) {
            mRandom = 5;
        } else {
            mRandom = mRandom % 5;
        }

        myView.mAnimationRoate = new RotateAnimation(0.0f, +(1800.0f + 72 * mRandom), Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
        //set the time of anim
        myView.mAnimationRoate.setDuration(3000);
        myView.mAnimationRoate.setFillAfter(true);//动画完成后不恢复原状
        myView.startAnimation(myView.mAnimationRoate);

        setmAnimation1();
    }//onCreate

    private void setmAnimation1() {
        mRandom = (int) (Math.random() * 100);
        if (mRandom % 5 == 0) {
            mRandom = 5;
        } else {
            mRandom = mRandom % 5;
        }

        myView.mAnimationRoate = new RotateAnimation(0.0f, +(1800.0f + 72 * mRandom), Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
        myView.mAnimationRoate.setDuration(3000);
        myView.mAnimationRoate.setFillAfter(true);//动画完成后不恢复原状
        myView.startAnimation(myView.mAnimationRoate);
    }

}
